document.addEventListener('DOMContentLoaded', function() {
    const carouselInner = document.querySelector('.carousel-inner');
    const images = document.querySelectorAll('.carousel-inner img');
    const prevBtn = document.querySelector('.carousel-prev');
    const nextBtn = document.querySelector('.carousel-next');
    let currentIndex = 0;

        // 启动自动轮播
    function startAutoSlide() {
        slideInterval = setInterval(nextSlide, 3000);
    }

    // 停止自动轮播
    function stopAutoSlide() {
        clearInterval(slideInterval);
    }

    // 初始化：显示第一张图片
    images[currentIndex].classList.add('active');

    // 下一张
    function nextSlide() {
        images[currentIndex].classList.remove('active');
        currentIndex = (currentIndex + 1) % images.length;
        images[currentIndex].classList.add('active');
    }

    // 上一张
    function prevSlide() {
        images[currentIndex].classList.remove('active');
        currentIndex = (currentIndex - 1 + images.length) % images.length;
        images[currentIndex].classList.add('active');
    }

    // 按钮事件
 // 按钮事件（点击时重置计时器）
    nextBtn.addEventListener('click', function() {
        stopAutoSlide();
        nextSlide();
        startAutoSlide();
    });

    prevBtn.addEventListener('click', function() {
        stopAutoSlide();
        prevSlide();
        startAutoSlide();
    });
    // 自动轮播（可选）
    startAutoSlide();
    // 鼠标悬停时停止轮播   
    carouselInner.addEventListener('mouseover', stopAutoSlide);
    // 鼠标离开时重新开始轮播   
    carouselInner.addEventListener('mouseout', startAutoSlide);

});